from lib.utils import browser
from lib.utils import get_logger
from DrissionPage.common import Keys

logger = get_logger(__name__)

def publish_to_weibo(title, content, tags, image_path):
    tab = browser.latest_tab
    tab.get("https://weibo.com/")

    ele = tab.ele("@tag()=textarea")
    ele.click()
    ele.input(title)
    tab.wait(4)

    ele.input(Keys.ENTER, clear=False)
    ele.input(content)
    tab.wait(4)

    ele.input(Keys.ENTER, clear=False)
    for tag in tags:
        ele.input(tag)
        tab.wait(2)
        ele.input(" ", clear=False)

    tab.ele("@text()=图片").click.to_upload(image_path)
    tab.wait(4)

    tab.ele("@text()=发送").click()



